package com.hainatong.jcmvvmbase;

import android.content.Intent;
import com.google.android.material.snackbar.Snackbar;
import com.hainatong.jcmvvmbase.databinding.FragmentPageBinding;
import com.hainatong.jcmvvmbase.dbtoolroom.User;
import com.hainatong.mvvmbase.base.BaseMvvmLazyFragment;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.hainatong.mvvmbase.rxbus.RxBus;
import com.hainatong.mvvmbase.rxbus.RxBusBaseMessage;

public class LazyFragment extends BaseMvvmLazyFragment<FragmentPageBinding, FirstViewModel>
{

    public static LazyFragment newInstance()
    {
        LazyFragment fragment = new LazyFragment();
        return fragment;
    }

    @Override
    public int getLayoutId()
    {
        return R.layout.fragment_page;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {

        super.onViewCreated(view, savedInstanceState);
        viewModel.text.set("Test");
        viewDataBinding.setViewModel( viewModel );
        initView();
    }

    private void initView()
    {
        viewDataBinding.text2.setOnClickListener( view -> {
            /*
            User one = new User(3,"铂金",22,"棍",85);
            viewModel.saveUser( one )
                     .observe(getViewLifecycleOwner(),result ->{
                         viewModel.text.set( result.getUsername() );
                         RxBus.getDefault().post( Constants.INFO1,new RxBusBaseMessage( 100,result));
                     });
                     */
            startActivity(new Intent(getActivity(),SignatureActivity.class));

            Snackbar.make(viewDataBinding.getRoot(), "点击了文字", Snackbar.LENGTH_LONG).show();

        } );



    }

    @Override
    protected void initViewBeforeLazyLoad()
    {

    }

    @Override
    protected void onFragmentFirstVisible()
    {
        super.onFragmentFirstVisible();

        Log.e("LazyFragment","onFragmentFirstVisible()方法开始");

        /*
        viewModel.getInfoByNet("LazyFragment的onFragmentFirstVisible")
                .observe(this,result ->{
                    viewModel.text.set( result );
                });
        */
        /*
        Observable.empty()
                  .timer(3000, TimeUnit.MICROSECONDS)
                  .compose(RxSchedulersUtils.Obs_io_main())
                  .doOnComplete(()->{
                  })
                  .subscribe();
        */

        //mLoadService.showSuccess();

    }

    @Override
    public int getBindingVariable()
    {
        return 0;
    }

    @Override
    protected void onRetryBtnClick()
    {

    }
}
